package com.itcast.springboot.waste_recovery.controller;


import com.itcast.springboot.waste_recovery.common.CommonResult;
import com.itcast.springboot.waste_recovery.domain.Feedback;
import com.itcast.springboot.waste_recovery.service.FeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 用户反馈 前端控制器
 * </p>
 *
 * @author 小破烂
 * @since 2020-08-19
 */
@RestController
@RequestMapping("/waste_recovery/feedback")
@Slf4j
@Api(tags = "用户反馈类接口")
public class FeedbackController {

    @Resource(name = "feedbackServiceImpl")
    FeedbackService feedbackService;

    @PostMapping("/customer/{user_id}/{feedback_content}")
    @ApiOperation(value = "意见反馈")
    //对方法中参数进行设置
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_id", value = "用户id"),
            @ApiImplicitParam(name = "feedback_content", value = "用户反馈内容")
    })
    @RequiresPermissions("user-operated")       //拥有 user-operated 才可以访问
    public CommonResult insertFeedback(@PathVariable(value = "user_id") Integer userId,
            @PathVariable(value = "feedback_content") String feedbackContent){
        Feedback feedback = new Feedback();
        feedback.setFeedbackUserId(userId);
        feedback.setFeedbackContent(feedbackContent);
        Integer result = feedbackService.insertFeedback(feedback);
        if (result <= 0){
            return CommonResult.CommonFail();
        }
        return CommonResult.CommonSuccess();
    }
}

